/*******************************************************************************
* 1. 시 스 템 : 농협보험 이미지처리 시스템
* 2. 프로그램 : CAgentEnv.java
* 3. 개 요 : Agent 환경 셋팅
* 4. 작 성 자 : Son Young Hwee
* 5. 작 성 일 : 2011. 09. 30
* 6. 소스버전 : 1.0 
********************************************************************************/

package com.nhim.common;

import com.nhim.utility.STRUtil;


public class CAgentEnv
{
	public String HOSTNAME;
	
	public String LOG_DIR;
	
	public String WORKDIR_ROOT;

	// Agent Sleep time
	public String liClmAgentSleepTime;
	public String liNebAgentSleepTime;
	
	// DATABASE : Image System
	public String dbDriver;
	public String dbUrl;
	public String dbUser;
	public String dbPasswd;
	public String dbLogPath;
	public int minConnections = 5;
	public int maxConnections = 30;
	
	public String logDelTime;
	
	public CAgentEnv(){
		String system = STRUtil.NVL(System.getProperty("app.instance"), "PROD");
		//String appNo = STRUtil.NVL(System.getProperty("app.no"), "");
		
		HOSTNAME = STRUtil.NVL(getHostName(), "");
		
		Environment env = EnvManager.getEnvironment();

		//LOG_DIR			= env.getProperty("LOG_DIR");
		LOG_DIR				= env.getProperty(system+"_LOG_DIR");
		//IF_URL				= env.getProperty(system+"_IF_URL");
		WORKDIR_ROOT		= env.getProperty(system+"_WORKDIR_ROOT");
		
		liClmAgentSleepTime = env.getProperty("LICLM_AGENT_SLEEP_TIME");
		liNebAgentSleepTime = env.getProperty("LINEB_AGENT_SLEEP_TIME");	
		
		dbDriver		= env.getProperty(system+"_DB_DRIVER");
		dbUrl			= env.getProperty(system+"_DB_URL");
		dbUser			= env.getProperty(system+"_DB_USER");
		dbPasswd		= env.getProperty(system+"_DB_PASSWORD");
		dbLogPath		= env.getProperty(system+"_DB_LOGFILE");
		String t_minconnections = env.getProperty(system+"_DB_MINCONNECTIONS");
		String t_maxconnections = env.getProperty(system+"_DB_MAXCONNECTIONS");
		if(t_minconnections != null ) minConnections = Integer.parseInt(t_minconnections);
		if(t_maxconnections != null ) maxConnections = Integer.parseInt(t_maxconnections);
				
		logDelTime		= env.getProperty("LOG.DEL.TIME");		
	}	

	public String getHostName() {
		String hostName = "";
		try {
			Runtime rt = java.lang.Runtime.getRuntime();
			Process proc = rt.exec("hostname");
			int inp;
			while ((inp = proc.getInputStream().read()) != -1) {
				hostName += (char) inp;
			}
			proc.waitFor();
		} catch (Exception e) {
			e.printStackTrace();
		}

		return hostName.trim();
	}	
}
